import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default {
    state: {
        menuList: [],
        permList: [],
        hasRoute: false,
        //全局tabs
        editableTabsValue: 'Index',
        editableTabs: [{
            title: '首页',
            name: 'Index'
        }]
    },
    mutations: {
        setMenuList(state,menus) {
            state.menuList = menus
        },
        setPermList(state,perms) {
            state.permList = perms
        },
        changeRouteStatus(state,hasRoute) {
            state.hasRoute = hasRoute

            sessionStorage.setItem("hasRoute",hasRoute)
        },
        //添加标签
        addTab(state,tab) {
            //若已经存在标签，则不添加
            let index = state.editableTabs.findIndex(e => e.name === tab.name)
            //-1 则为未找到
            if (index === -1) {
                state.editableTabs.push({
                    title: tab.title,
                    name: tab.name,
                });
            }
            state.editableTabsValue = tab.name;
        },
        //退出登录后清除信息
        resetState: (state) => {
            state.menuList = [],
            state.permList = [],
            state.hasRoute = false,
            state.editableTabsValue = 'Index',
            state.editableTabs = [{
                name: 'Index',
                title: '首页'
            }]
        }
    },
    actions: {
    }
}
